package Leetcode第二期;

import java.util.*;

/**
 * @author : K k
 * @date : 14:09 2020/9/20
 */
public class 子集_78 {
    Deque<Integer> queue=new ArrayDeque<>();

    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res=new ArrayList<>();
        dfsSolver(res,nums,0,nums.length);
        System.out.println(res);
        return res;
    }

    private void dfsSolver(List<List<Integer>> res, int[] nums, int index, int len) {
        res.add(new ArrayList<>(queue));

        if (queue.size()==len){
            return;
        }

        for (int i=index;i<len;i++){
            queue.addLast(nums[i]);
            dfsSolver(res,nums,i+1,len);
            queue.removeLast();
        }
    }

    public static void main(String[] args) {
        子集_78 x=new 子集_78();
        x.subsets(new int[]{1,2,3});
    }
}
